package com.happok.onlineclass.usermanagement.customform.controller;

import com.happok.common.result.CommonResult;
import com.happok.microgateway.service.RoutingDelegate;
import com.happok.onlineclass.usermanagement.common.dto.Contants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 人员自定义表单
 * 参考在线课堂自定义表单：http://192.168.1.125:3000/project/129/interface/api/cat_563
 *
 * @author : chenac
 * @module 在线课堂/用户管理
 * @date : 2021/7/6 11:32
 */
@RestController
@Api(tags = "人员自定义表单")
@RequestMapping(value = "/user-management/users/custom-forms/fields")
public class CustomFormController {

    @Autowired
    private RoutingDelegate routingDelegate;

    /**
     * 添加表单字段
     * 参考：http://192.168.1.125:3000/project/129/interface/api/1819
     *
     * @param request
     * @author: chenac
     * @date: 11:39
     * @execption:
     * @return: org.springframework.http.ResponseEntity<com.happok.common.result.CommonResult>
     */
    @PostMapping(value = "/v1")
    @ApiOperation(value = "添加表单字段")
    public ResponseEntity<CommonResult> addCustomFormFields(HttpServletRequest request) {
        String url = Contants.CUSTOM_FORM_USER_INFO + "/fields/v1";
        return routingDelegate.forward(request, url, Contants.CUSTOM_FORMS);
    }

    /**
     * 查询表单字段列表
     * 参考：http://192.168.1.125:3000/project/129/interface/api/1817
     *
     * @param request
     * @author: chenac
     * @date: 11:39
     * @execption:
     * @return: org.springframework.http.ResponseEntity<com.happok.common.result.CommonResult>
     */
    @GetMapping(value = "/batch/v1")
    @ApiOperation(value = "查询表单字段列表")
    public ResponseEntity<CommonResult> getCustomFormFields(HttpServletRequest request) {
        String url = Contants.CUSTOM_FORM_USER_INFO + "/fields/v1";
        return routingDelegate.forward(request, url, Contants.CUSTOM_FORMS);
    }

    /**
     * 更新表单字段顺序
     * 参考：http://192.168.1.125:3000/project/129/interface/api/1821
     *
     * @param request
     * @author: chenac
     * @date: 11:39
     * @execption:
     * @return: org.springframework.http.ResponseEntity<com.happok.common.result.CommonResult>
     */
    @PutMapping(value = "/{fieldId}/order/v1")
    @ApiOperation(value = "更新表单字段顺序")
    public ResponseEntity<CommonResult> listCustomFormFields(HttpServletRequest request,
                                                             @PathVariable String fieldId) {
        String url = Contants.CUSTOM_FORM_USER_INFO + "/fields/" + fieldId + "/order/v1";
        return routingDelegate.forward(request, url, Contants.CUSTOM_FORMS);
    }

    /**
     * 更新表单字段
     * 参考：http://192.168.1.125:3000/project/129/interface/api/1823
     *
     * @param request
     * @author: chenac
     * @date: 11:39
     * @execption:
     * @return: org.springframework.http.ResponseEntity<com.happok.common.result.CommonResult>
     */
    @PutMapping(value = "/{fieldId}/v1")
    @ApiOperation(value = "更新表单字段")
    public ResponseEntity<CommonResult> updateCustomFormFields(HttpServletRequest request,
                                                               @PathVariable String fieldId) {
        String url = Contants.CUSTOM_FORM_USER_INFO + "/fields/" + fieldId + "/v1";
        return routingDelegate.forward(request, url, Contants.CUSTOM_FORMS);
    }

    /**
     * 删除表单字段
     * 参考：http://192.168.1.125:3000/project/129/interface/api/1825
     *
     * @param request
     * @author: chenac
     * @date: 11:39
     * @execption:
     * @return: org.springframework.http.ResponseEntity<com.happok.common.result.CommonResult>
     */
    @DeleteMapping(value = "/{fieldId}/v1")
    @ApiOperation(value = "删除表单字段")
    public ResponseEntity<CommonResult> deleteCustomFormFields(HttpServletRequest request,
                                                               @PathVariable String fieldId) {
        String url = Contants.CUSTOM_FORM_USER_INFO + "/fields/" + fieldId + "/v1";
        return routingDelegate.forward(request, url, Contants.CUSTOM_FORMS);
    }
}